import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Bigscreen from '../components/BigScreen/BigScreen.vue'
import Bigscreenworld from '../components/BigScreen/BigScreenWorld.vue'
import Users from '../components/user/Users'
import CNcov from '../components/cov/CNcov.vue'
import JPcov from '../components/cov/JPcov.vue'
import AUScov from '../components/cov/AUScov.vue'
import CNcity from '../components/cov/cncity.vue'
import Worldcov from '../components/cov/Worldcov.vue'
import USAcov from '../components/cov/USAcov.vue'
import News from '../components/news/News.vue'
import Rumors from '../components/news/rumors.vue'
import Vacc from '../components/vacc/Vacc.vue'
import WorldVacc from '../components/vacc/WorldVacc.vue'


Vue.use(VueRouter)
// Vue.use(screenfull)
const routes = [
    { path: '/login', component: Login },
    {
        path: '/home',
        component: Home,
        children: [
            { path: '/welcome', component: Welcome },
            { path: '/users', component: Users },
            { path: '/cncov', component: CNcov },
            { path: '/cncity', component: CNcity },
            { path: '/usacov', component: USAcov },
            { path: '/news', component: News },
            { path: '/rumors', component: Rumors },
            { path: '/vacc', component: Vacc },
            { path: '/worldvacc', component: WorldVacc },
            { path: '/worldcov', component: Worldcov },
            { path: '/jpcov', component: JPcov },
            { path: '/auscov', component: AUScov },
        ]
    },
    { path: '/bigscreen', component: Bigscreen },
    { path: '/bigscreenworld', component: Bigscreenworld },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    let token = window.sessionStorage.getItem('token');
    if (to.path === '/login') {
        if (token) {
            next('/welcome')
        } else {
            next();
        }
    } else if (to.path === '/bigscreen') {
        next();
    } else if (to.path === '/bigscreenworld') {
        next();
    } else if (to.path === '/welcome') {
        if (token) {
            next()
        } else {
            next('/login');
        }
    } else if (to.path === '/') {
        next('/bigscreen')
    } else {
        //查看是否有token   sesssionstrage
        // let token = window.sessionStorage.getItem('token');
        if (token) {
            next();
        } else {
            next('/bigscreen')
        }
    }

})

export default router